

'''-- brand表
CREATE TABLE brand (
    brand_id INT PRIMARY KEY,
    brand_name VARCHAR(100) NOT NULL,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);'''
class BrandTableMethods:

    def __init__(self, conn, cur):

        self.cursor = cur
        
        self.conn = conn

    
    # insert brand
    def insert_brand(self, brand_name):

        sql = "INSERT INTO brand (brand_name) VALUES (%s)"

        self.cursor.execute(sql, (brand_name,))

        self.conn.commit()

    def get_brand_by_id(self, brand_id):

        sql = "SELECT * FROM brand WHERE brand_id = %s"

        self.cursor.execute(sql, (brand_id,))

        result = self.cursor.fetchone()


        return result
    
    def get_brand_by_name(self, brand_name):

        sql = "SELECT * FROM brand WHERE brand_name = %s"

        self.cursor.execute(sql, (brand_name,))

        return self.cursor.fetchone()
    

    def delete_brand_by_id(self, brand_id):

        sql = "DELETE FROM brand WHERE brand_id = %s"

        self.cursor.execute(sql, (brand_id,))

        self.conn.commit()

    def update_brand_by_id(self, brand_id, brand_name):

        sql = "UPDATE brand SET brand_name = %s WHERE brand_id = %s"

        self.cursor.execute(sql, (brand_name, brand_id))

        self.conn.commit()

    def delete_brand_by_id(self, brand_id):

        sql = "DELETE FROM brand WHERE brand_id = %s"

        self.cursor.execute(sql, (brand_id,))

        self.conn.commit()


